from rest_framework import serializers

from .models import Area


class AreaSerializers(serializers.ModelSerializer):
    """请求查询列表序列化器"""

    class Meta:
        # 指定进行序列化输出的模型类
        model = Area
        # 指定序列化输出的字段
        fields = ('id', 'name')


class SubAreaSerializers(serializers.ModelSerializer):
    """市区查询子集的序列化器"""

    # 指定关联字段输出的序列化方式
    subs = AreaSerializers(many=True, read_only=True)

    class Meta:
        # 指定进行序列化输出的模型类
        model = Area
        # 指定序列化输出的字段
        fields = ('id', 'name', 'subs')
